package utils

import (
	"go-chat/common"

	"github.com/gin-gonic/gin"
)

func GetID(c *gin.Context) uint {
	userIdRaw, exists := c.Get("id")
	if exists {
		if userId, ok := userIdRaw.(uint); ok {
			return userId
		}
	} else {
		common.Fail(c, 401, "用户未登录！")
		return 0
	}
	return 0
}
